using UnityEngine;
using System.Collections;
using System;
public class smoothFollow : MonoBehaviour {
	
Transform target;
float distance = 7.0f;
float height = 5.0f;
float damping = 5.0f;
bool smoothRotation = true;
float rotationDamping = 10.0f;

void Update () {
	if(!target)
	{
		String playerEnter = Network.player.ToString();
		target = GameObject.Find("Personagem"+playerEnter+"(Clone)").transform;
	}
	Vector3 wantedPosition = target.TransformPoint(0, height, -distance);
	transform.position = Vector3.Lerp(transform.position, wantedPosition, Time.deltaTime * damping);

	if (smoothRotation) {
		Quaternion wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up);
		transform.rotation = Quaternion.Slerp (transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);
	}

	else transform.LookAt (target, target.up);
}

}
